package cn.ljn.basic.listen;

import cn.ljn.basic.service.IPermissionScanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

@Component
@Slf4j
public class PermissionScanInitInstener implements ServletContextListener {

  @Autowired
  private IPermissionScanService permissionScanService;



  @Override
  public void contextInitialized(ServletContextEvent servletContextEvent) {
      // 项目启动时执行permission数据添加方法
      new Thread(new Runnable() {
        @Override
        public void run() {
          log.info("contextInitialized start...");
          // 执行permission数据添加方法
          permissionScanService.scanPermission();
          log.info("contextInitialized stop...");
        }
      }).start();
    }

  @Override
  public void contextDestroyed(ServletContextEvent servletContextEvent) {
    log.info("PermissionScanInitInstener stop..");
  }
}
